package com.yanqu.road.server.cmd.activity.tonbing.cross;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.TonBingProto;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.Command;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;
import io.netty.channel.ChannelHandlerContext;


@Cmd(code = GameProtocol.S_CROSS_TON_BING_RED_PACKET_SYNC, desc = "")
public class TonBingRedPacketSyncCmd implements Command {

    @Override
    public void execute(ChannelHandlerContext ctx, YanQuMessage packet) throws Exception {
        TonBingProto.CrossTonBingRedPacketSyncMsg syncMsg = TonBingProto.CrossTonBingRedPacketSyncMsg.parseFrom(packet.getBytes());
        TonBingProto.TonBingRedPacketSyncMsg.Builder syncUserMsg = TonBingProto.TonBingRedPacketSyncMsg.newBuilder();
        for(TonBingProto.TonBingRedPacketMsg redPacketMsg : syncMsg.getRedPacketsList()){
            syncUserMsg.addRedPackets(redPacketMsg);
        }
        for(long userId : syncMsg.getUserIdsList()){
            GamePlayer player = GamePlayerMgr.getOnlinePlayer(userId);
            if(player != null){
                player.sendPacket(ClientProtocol.U_TON_BING_SYNC_CAMP_BOX, syncUserMsg);
            }
        }
    }
}
